﻿using System;
using NUnit.Framework;

namespace PoolKit.Tests
{
    [TestFixture]
    public class DisposableCookieTests
    {
        [Test]
        public void MakeSureANewlyConstructedCookieIsNotDisposedAndBehavesAccordingly()
        {
            var cookie = new DisposableCookie(String.Empty);

            Assert.IsFalse(cookie.IsDisposed);
            cookie.ThrowIfDisposed();
        }

        [Test]
        public void MakeSureADisposedCookieReportsItHasBeenDisposedAndBehavesAccordingly()
        {
            var cookie = new DisposableCookie(String.Empty);
            Assert.IsFalse(cookie.IsDisposed);

            cookie.MarkAsDisposed();
            Assert.IsTrue(cookie.IsDisposed);

            Assert.Throws<ObjectDisposedException>(cookie.ThrowIfDisposed);
        }

        [Test]
        public void MakeSureMessagePassedToCookieUponConstructionIsTheOneItRaisesObjectDisposedExceptionWith()
        {
            var cookie = new DisposableCookie("Words matter");

            cookie.MarkAsDisposed();

            Assert.Throws<ObjectDisposedException>(cookie.ThrowIfDisposed, "Words matter");
        }
    }
}